﻿Imports System.Data
Imports System.Data.SqlClient
Public Class itensCaixaDAL
#Region "localiza itens"
    Function localiza_itens(ByVal cxacod As Integer) As DataTable
        Dim tab As DataTable
        Dim cmd As SqlCommand
        Try
            cmd = New SqlCommand
            cmd.CommandText = "select * from Financeiro.Ofi_ItensCaixa where cai_codigo=@codigo and itec_valor=@itensvalor and itec_data=@data and opc_codigo=@operacao"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = cxacod
            tab = objconexao.retdadosTab(cmd)
        Catch ex As Exception
            Throw New Exception("", ex)
        Finally
            cmd = Nothing
        End Try
        Return tab
    End Function
#End Region
#Region "inserir"
    Function inserir(ByVal caicodigo As Integer, ByVal itecvalor As Decimal, ByVal itecdata As Date, ByVal operacao As Integer) As Integer
        Dim cmd As SqlCommand
        Dim Ret As Integer
        Try
            cmd = New SqlCommand
            cmd.CommandText = "insert into Financeiro.Ofi_ItensCaixa(cai_codigo, itec_valor, itec_data,sta_codigo) " & _
                " values (@caicodigo, @itecvalor,@itecdata,@opccodigo)"
            cmd.Parameters.Add(New SqlParameter("@caicodigo", SqlDbType.Int)).Value = caicodigo
            cmd.Parameters.Add(New SqlParameter("@itecvalor", SqlDbType.Decimal)).Value = itecvalor
            cmd.Parameters.Add(New SqlParameter("@itecdata", SqlDbType.Date)).Value = itecdata
            cmd.Parameters.Add(New SqlParameter("@opccodigo", SqlDbType.Int)).Value = operacao
            Ret = objconexao.executaCmd(cmd)
        Catch ex As Exception
            Throw New Exception("Erro. ", ex)
        Finally
            cmd = Nothing
        End Try
        Return Ret
    End Function
#End Region
#Region "localiza todos"
    Function localTodos(ByVal cod As Integer) As DataTable
        Dim tab As DataTable
        Dim cmd As SqlCommand
        Try
            cmd = New SqlCommand
            cmd.CommandText = "select * from Financeiro.Ofi_ItensCaixa where " & _
                "cai_codigo = @codigo"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = cod
            tab = objconexao.retdadosTab(cmd)
        Catch ex As Exception
            Throw New Exception("", ex)
        Finally
            cmd = Nothing
        End Try
        Return tab
    End Function
#End Region
End Class
